package com.Controller;
import com.Service.CommentService;
import com.pojo.FindReply;
import com.pojo.Remark;
import com.pojo.Reply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.sql.SQLException;
import java.util.List;

@Controller
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;
    @PostMapping("add")
    @ResponseBody
    public void insertComment(@RequestParam String username, @RequestParam String bookId, @RequestParam String commentText,
    @RequestParam String timestamp) throws SQLException {
           commentService.insertComment(username,bookId,commentText,timestamp);
    }
    @PostMapping("/updatepiao")
    @ResponseBody
    public void updateRecommendQuan(@RequestParam String bookId,@RequestParam String recommendPiao,@RequestParam String username) throws SQLException {
            commentService.updateRecommend(bookId,recommendPiao,username);
    }
    @PostMapping("/insertReply")
    @ResponseBody
    public void insertReply(@RequestBody Reply reply) throws SQLException {
       commentService.insertReply(reply);
    }
    @GetMapping("/getReplyByCommentId")
    public ModelAndView getReplyById(@RequestParam String commendId) throws SQLException {
       ModelAndView modelAndView=new ModelAndView("reply");
       List<FindReply> findReplyList=commentService.getReplyById(commendId);
       modelAndView.addObject("findReplyList",findReplyList);
       return modelAndView;
    }
}
